import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hook_rent/widgets/image_widget.dart';

class SearchBarWidget extends StatefulWidget {
  final bool? showLocation; //是否显示位置
  final VoidCallback? goBackCallback; //回退
  final String? inputValue; //搜索框值
  final String defaultInputValue; //默认显示值
  final VoidCallback? onCancel; //取消按钮
  final bool? showMap; //是否显示地图按钮
  final Function? onSearch; //点击搜索框触发
  final ValueChanged<String>? onSearchSubmit; // 点击回车触发

  const SearchBarWidget(
      {super.key,
      this.showLocation,
      this.goBackCallback,
      this.inputValue,
      required this.defaultInputValue,
      this.onCancel,
      this.showMap,
      this.onSearch,
      this.onSearchSubmit});

  @override
  State<SearchBarWidget> createState() => _SearchBarWidgetState();
}

class _SearchBarWidgetState extends State<SearchBarWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: [
          if (widget.showLocation == true)
            Padding(
              padding: EdgeInsets.only(right: 10.w),
              child: GestureDetector(
                onTap: () {},
                child: Row(
                  children: [
                    Icon(
                      Icons.location_on,
                      color: Colors.green,
                      size: 16.sp,
                    ),
                    Text(
                      '北京',
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 16.sp,
                      ),
                    )
                  ],
                ),
              ),
            ),
          //返回按钮
          if (widget.goBackCallback != null)
            Padding(
              padding: EdgeInsets.only(right: 10.w),
              child: GestureDetector(
                onTap: widget.goBackCallback,
                child: const Icon(
                  Icons.chevron_left,
                  color: Colors.black87,
                ),
              ),
            ),
          //搜索框
          Expanded(
            child: Container(
              padding: EdgeInsets.only(right: 10.w),
              child: TextField(
                  decoration: InputDecoration(
                hintText: widget.defaultInputValue,
              )),
            ),
          ),
          //取消
          if (widget.onCancel != null)
            Padding(
              padding: EdgeInsets.only(right: 10.w),
              child: GestureDetector(
                onTap: widget.onCancel,
                child: Text(
                  '取消',
                  style: TextStyle(
                    color: Colors.black87,
                    fontSize: 16.sp,
                  ),
                ),
              ),
            ),

          //地图按钮
          if (widget.showMap == true)
            GestureDetector(
              onTap: () {},
              child: const ImageWidget(
                'static/icons/widget_search_bar_map.png',
              ),
            ),
        ],
      ),
    );
  }
}
